<template>
  <div class="app-container">
    <uc-table url="admin/camera/getPageData" name="视频设备管理" ref="cameraTable" pageable table-border :search-form="searchForm"
              @selection-change="handleSelectionChange">
      <template slot="searchForm">
        <el-form size="mini" :inline="true" :model="searchForm" class="demo-form-inline filter-container">
          <!--搜索输入框-->
          <el-form-item>
            <el-input type="text" v-model="searchForm.name" placeholder="请输入设备名称" clearable
                      @clear="clearInput()"></el-input>
          </el-form-item>
          <!--搜索按钮--新增按钮-->
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" class="filter-item" @click="handleSearch()">查询</el-button>
            <el-button type="success" icon="el-icon-plus" class="filter-item" @click="handleAdd()">新 增</el-button>
          </el-form-item>
        </el-form>
      </template>
      <template slot="columns">
        <el-table-column type="selection" width="55" align="center"/>
        <el-table-column prop="name" label="设备名称" align="left" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="code" label="设备编码" align="left" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="regionName" label="所属区域" align="left" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column label="操作" width="380" align="left" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <!--编辑按钮-->
            <el-button size="mini" icon="el-icon-edit" type="primary" @click="handleEdit(scope.row)">编辑</el-button>
            <el-button size="mini" icon="el-icon-info" type="success" @click="handleInfo(scope.row)">详情</el-button>
            <el-button size="mini" type="danger" icon="el-icon-delete" :loading="deleteLoading"
                       @click="handleDelete(scope.row)">删除
            </el-button>
          </template>
        </el-table-column>
      </template>
    </uc-table>
  </div>
</template>
<script>
import UcTable from "@/components/UcTable/index.vue";
import {deleteData} from "@/api/camera";

export default {
  name: "cameraList",
  components: {UcTable},
  data() {
    return {
      searchForm: {
        name: ""
      },
      deleteLoading: false,
      ucIds: [],
      statusOptions: [],
      codes: []
    }
  },
  created() {
    this.getDicts("contract_status").then(response => {
      this.statusOptions = response.data.data;
    });
  },
  methods: {
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.codes = selection.map(item => item.name)
    },
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    handleSearch() {
      this.$refs.cameraTable.getTableData(1)
    },
    handleAdd() {
      this.$router.push("/securityAlarm/cameraedit/0")
    },
    handleEdit(val) {
      this.$router.push("/securityAlarm/cameraedit/" + val.ucId)
    },
    handleInfo(val) {
      this.$router.push("/securityAlarm/camerainfo/" + val.ucId)
    },
    clearInput() {
      //清除输入框
      this.searchForm.name = null
      this.handleSearch()
    },
    handleDelete(val) {
      const ids = val.id || this.ids;
      const names = val.code || this.codes;
      this.$confirm('是否确认删除编号为【' + names + '】的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return deleteData(ids);
      }).then((res) => {
        if(res.data.code == 200){
          this.handleSearch();
          this.$notify.success({
            title: '成功',
            message: "删除成功"
          })
        }else{
          this.$notify.error({
            title: '成功',
            message: res.data.msg
          })
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
